package com.ruoyi.slope.device.errLog.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.device.errLog.domain.SlopeDeviceErrlog;
import com.ruoyi.slope.device.errLog.service.ISlopeDeviceErrlogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 异常日志Controller
 * 
 * @author psy
 * @date 2025-05-01
 */
@RestController
@RequestMapping("/device/errLog")
public class SlopeDeviceErrlogController extends BaseController
{    
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeDeviceErrlogService slopeDeviceErrlogService;

    /**
     * 查询异常日志列表
     */
    @PreAuthorize("@ss.hasPermi('sensor:sensor:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeDeviceErrlog slopeDeviceErrlog)
    {
        startPage();
        List<SlopeDeviceErrlog> list = slopeDeviceErrlogService.selectSlopeDeviceErrlogList(slopeDeviceErrlog);
        return getDataTable(list);
    }

    /**
     * 导出异常日志列表
     */
    @PreAuthorize("@ss.hasPermi('sensor:sensor:list')")
    @Log(title = "异常日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeDeviceErrlog slopeDeviceErrlog)
    {
        List<SlopeDeviceErrlog> list = slopeDeviceErrlogService.selectSlopeDeviceErrlogList(slopeDeviceErrlog);
        ExcelUtil<SlopeDeviceErrlog> util = new ExcelUtil<SlopeDeviceErrlog>(SlopeDeviceErrlog.class);
        String path = util.exportExcel(response, list, "异常日志数据"); 
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

}
